<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/1/11 0011
 * Time: 18:06
 */

namespace app\index\model;

use think\facade\Cache;
use think\Model;

class GoodsPropValue extends Model
{
    protected $pk = 'pid';

    public static function getGoodsPropValues()
    {
        //构建数据库连接
        $model = self::field(true)->order('sort_order');

        //返回数据
        $arrTmp = [];
        $result = $model->select()->toArray();
        foreach($result as $v){
            $arrTmp[$v['vid']] = $v['prop_value'];
        }

        return $arrTmp;
    }

    public static function getGoodsPropValues2()
    {
        if (Cache::has('prop_value_arr')){
            return Cache::get('prop_value_arr');
        }
        // 数组降维处理  $prop_value_arr  一维关联数组
        $prop_value_list = self::field('vid,prop_value')
                                ->where('status',1)
                                ->order('sort_order')
                                ->select();
        $prop_value_arr = [];
        foreach($prop_value_list as $value){
            $prop_value_arr[$value['vid']] = $value['prop_value'];
        }
        Cache::set('prop_value_arr',$prop_value_arr,600);
        return $prop_value_arr;
    }


}